//package down.sallai.ml.filter;
//
//import com.alibaba.fastjson.JSONObject;
//import lombok.extern.slf4j.Slf4j;
//
//import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
//
///**
// * @description: proxy filter$
// * @author: sallai
// * @time: 2022年1月3日 0003 下午 05:10:46 秒
// */
//@Slf4j
//@Component
//public class ProxyFilter implements Filter {
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
//            throws IOException, ServletException {
//        HttpServletRequest request1 = (HttpServletRequest) request;
//        if(request1.getServletPath().indexOf("/github")==-1) {
//            chain.doFilter(request,response);
//            log.info("不是代理路径，跳过");
//            return;
//        }
//        //将参数response的类型强制转换为使用Http协议的HttpServletResponse类型
//        HttpServletResponse httpResp = (HttpServletResponse) response;
//        //创建包装器对象，包装原始的response对象
//        ResponseWrapper wrapper = new ResponseWrapper(httpResp);
//
//        chain.doFilter(request, wrapper);
//        // 获取response返回的内容并重新写入response, 若获取到的数据是乱码，可设置response的编码为系统默认编码集
//        String result = wrapper.getResponseData(response.getCharacterEncoding());
//        Object object = JSONObject.parse(result);
//        response.getOutputStream().write(result.getBytes());
//        response.getOutputStream().flush();
//        response.getOutputStream().close();
//
//        log.info(result);
//        log.info("exit filter");
//    }
//}
